package br.ufal.tci.nexos.arcolive;

import java.util.Hashtable;

import br.ufal.tci.nexos.arcolive.exception.ArCoLIVEException;

public class ArCoLIVEServiceClassPoll {

	private Hashtable classPoll;
	private static ArCoLIVEServiceClassPoll singleton = null;
	
	private ArCoLIVEServiceClassPoll() {
		this.classPoll = new Hashtable();
	}
	
	public static ArCoLIVEServiceClassPoll getInstance() {
		if (singleton == null) {
			singleton = new ArCoLIVEServiceClassPoll();
		}
		return singleton;
	}
	
	public void addServiceClass(String serviceName, String classpath) throws ArCoLIVEException {
		try {
			this.classPoll.put(serviceName, Class.forName(classpath));
		} catch (ClassNotFoundException e) {
			throw new ArCoLIVEException("Service class not found", e);
		}
	}
	
	public Class getServiceClass(String serviceName) {
		return (Class)this.classPoll.get(serviceName);
	}
	
}
